<?php
declare(strict_types=1);

namespace App\Resource\Lottery3\User;


use Illuminate\Http\Resources\Json\JsonResource;

class DetailResource extends JsonResource
{
    public function toArray($request)
    {
        return [
            "id" => $this->id,
            "code" => $this->user->user_code,
            "nickname" => $this->user->nickname,
            "total" => [
                "balance" => $this->balance,
                "count" => $this->count,
                "input" => $this->input,
                "output" => $this->output,
                "recoup_count" => $this->recoup_count,
                "recoup_output" => $this->recoup_output,
            ],
            "date" => [
                "date" => $this->date->date,
                "count" => $this->date->count,
                "input" => $this->date->input,
                "output" => $this->date->output,
                "recoup_count" => $this->date->recoup_count,
                "recoup_output" => $this->date->recoup_output,
            ],
        ];
    }

    static public function table($request)
    {
        $str = "";
        $str .= "<br>奖池信息: </br>";
        $str .= "<table border='1'>";
        $str .= "<tr>";
        $str .= "<th>奖池虚假投入（金币）</th>";
        $str .= "<th>奖池总投入（金币）</th>";
        $str .= "<th>奖池总产出（金币）</th>";
        $str .= "<th>奖池总盈亏（投入-产出金币）</th>";
        $str .= "</tr>";
        $str .= "<tr>";
        $str .= "<td>{$request->pool->fake_input}</td>";
        $str .= "<td>{$request->pool->input}</td>";
        $str .= "<td>{$request->pool->output}</td>";
        $str .= "<td>{$request->pool->profit}</td>";
        $str .= "</tr>";
        $str .= "</table>";


        $str .= "<br>用户信息: </br>";
        $str .= "<table border='1'>";
        $str .= "<tr>";
        $str .= "<th>用户ID</th>";
        $str .= "<th>用户编号</th>";
        $str .= "<th>用户昵称</th>";
        $str .= "</tr>";
        $str .= "<tr>";
        $str .= "<td>{$request->user->user_id}</td>";
        $str .= "<td>{$request->user->user_code}</td>";
        $str .= "<td>{$request->user->nickname}</td>";
        $str .= "</tr>";
        $str .= "</table>";

        $userProfit = $request->output - $request->input;
        $str .= "<br>用户详情:</br>";
        $str .= "<table border='1'>";
        $str .= "<tr>";
        $str .= "<th>用户总投入（金币</th>";
        $str .= "<th>用户总产出（金币）</th>";
        $str .= "<th>用户总盈亏（产出-投入;金币）</th>";
        $str .= "<th>用户补偿次数（金币）</th>";
        $str .= "<th>用户补偿价值（金币）</th>";
        $str .= "</tr>";
        $str .= "<tr>";
        $str .= "<td>{$request->input}</td>";
        $str .= "<td>{$request->output}</td>";
        $str .= "<td>{$userProfit}</td>";
        $str .= "<td>{$request->recoup_count}</td>";
        $str .= "<td>{$request->recoup_output}</td>";
        $str .= "</tr>";
        $str .= "</table>";

        $userDateProfit = $request->date->output - $request->date->input;
        $str .= "<br>用户今日详情({$request->data->date}):</br>";
        $str .= "<table border='1'>";
        $str .= "<tr>";
        $str .= "<th>用户今日投入（金币</th>";
        $str .= "<th>用户今日产出（金币）</th>";
        $str .= "<th>用户今日盈亏（产出-投入;金币）</th>";
        $str .= "<th>用户今日补偿次数（金币）</th>";
        $str .= "<th>用户今日补偿价值（金币）</th>";
        $str .= "</tr>";
        $str .= "<tr>";
        $str .= "<td>{$request->date->input}</td>";
        $str .= "<td>{$request->date->output}</td>";
        $str .= "<td>{$userDateProfit}</td>";
        $str .= "<td>{$request->date->recoup_count}</td>";
        $str .= "<td>{$request->date->recoup_output}</td>";
        $str .= "</tr>";
        $str .= "</table>";

        return $str;
    }
}